import { Component, OnInit, Injector, Type, TemplateRef, ViewChild, Input } from '@angular/core';
import { NgZorroPageBaseComponent } from '../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component';
import { HttpService } from "../../core/service/http.service";
import { Router, NavigationExtras } from "@angular/router";
import {
	AndOr, Compare, ExpressionPair, PagedResultDto, PagerSearchInput, ElementViewType, BaseComponentConfig,
	SystemFormControl, FieldType, ElementShowType, CustomNavigation, NavigatType, DrillSubjectOutput
} from "../..";
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import {
	FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators,
	FormControl
} from "@angular/forms";
import { SystemFormOutput } from "../../core/model/SystemFormDto";
import { DrillRoleComponent } from './drill-role.component';
import { ClassGetter } from '@angular/compiler/src/output/output_ast';
import { DrillFlowComponent } from './drill-flow.component';
import { ArSystemFormControl, LoadRemoteDataType } from '../../core/model/CommonDto';
import { DrillProjectOutput } from '../../core/model/DrillDto';



@Component({
	selector: 'app-drill-project',
	templateUrl: '../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component.html',
	styleUrls: ['../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component.scss']
})
export class DrillProjectComponent extends NgZorroPageBaseComponent implements OnInit {
	constructor(injector: Injector) {
		super(injector,
			new BaseComponentConfig(
				"DrillProject/GetAll",
				"DrillProject/Create",
				"DrillProject/Update",
				"DrillProject/Get",
				"DrillProject/Delete",
				"id",
				"",
				"实训项目管理",
				new Array<CustomNavigation>(
					new CustomNavigation('主题', '/app/drill/subject', ElementShowType.TableOperation, 'anticon anticon-bars', NavigatType.Route, 'subject'),
				)
			), new ArSystemFormControl([
				new SystemFormControl("projectName", "项目名称", FieldType.Text, true, 30, 0, "", "", false, null, LoadRemoteDataType.LoadAll, true, true, false),
				new SystemFormControl("backgroundImg", "背景图", FieldType.Image, false, 0, 0, "", "", false, null, LoadRemoteDataType.LoadAll, true, true, false),
				new SystemFormControl("backColor", "背景色", FieldType.Color, false, 30, 0, "", "", false, null, LoadRemoteDataType.LoadAll, true, false, false),
				new SystemFormControl("bannerImg", "banner", FieldType.Image, false, 0, 0, "", "", false, null, LoadRemoteDataType.LoadAll, true, true, false),
				new SystemFormControl("bottomImg", "底部图片", FieldType.Image, false, 0, 0, "", "", false, null, LoadRemoteDataType.LoadAll, true, true, false),
				new SystemFormControl("projectDesc", "演练描述", FieldType.Text, false, 300, 0, "", "", false, null, LoadRemoteDataType.LoadAll, true, true, false),
				// new SystemFormControl("projectBackground", "案例背景", FieldType.Text, false, 300, 0, "", "", false, null, LoadRemoteDataType.LoadAll, true, true, false),
				// new SystemFormControl("guide", "实训指导", FieldType.Text, false, 300, 0, "", "", false, null, LoadRemoteDataType.LoadAll, true, true, false),
				// new SystemFormControl("classResuorce", "课程资料", FieldType.Text, false, 300, 0, "", "", false, null, LoadRemoteDataType.LoadAll, true, true, false),
			]));
		this.storageName = "Project";
	}

	getNewEntity(): DrillProjectOutput {
		return new DrillProjectOutput();
	}

	async navigateCustom(url: string, pid: any) {
		const msgId = this.message.loading('正在获取数据', { nzDuration: 0 }).messageId;
		try {
			const findEntity = await this.httpService.get<DrillProjectOutput>(`${this.componentConfig.GetSingle}?input=${pid}`);
			if (findEntity) {
				const navigationExtras: NavigationExtras = {
					queryParams: { 'id': pid, 'caption': findEntity.projectName }
				};
				window.localStorage.setItem(this.storageName, JSON.stringify(this.listEntities));
				this.router.navigate([url], navigationExtras);
			} else {
				this.message.error('无法确定表单信息！请刷新列表！');
			}
		} finally {
			this.message.remove(msgId);
		}
	}

	showModalForComponent(entity: DrillSubjectOutput, tag: string) {
		// const keyValue = entity.id;
		// const component = <Type<any>>(tag === 'role' ? DrillRoleComponent : DrillFlowComponent);
		// const subscription = this.nzModalService.create({
		// 	nzTitle: `${entity.drillSubjectName}`,
		// 	nzContent: component,
		// 	nzComponentParams: {
		// 		pKeyFieldValue: keyValue,
		// 		caption: entity.drillSubjectName
		// 	},
		// 	nzFooter: null,
		// 	nzWidth: document.documentElement.clientWidth - 60,
		// });
	}
}
